SummonerMastery.constructor   A
last analyzed

Complexity

Conditions 1
Paths 2

Size

Total Lines 67

Duplication

Lines 67
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
nop 0
dl 67
loc 67
rs 9.2815

11 Functions

Rating   Name   Duplication   Size   Complexity  
A SummonerMastery.champion 5 5 2
A SummonerMastery.points 11 11 1
A SummonerMastery.points 3 3 1
B SummonerMastery.champion 27 27 2
A SummonerMastery.level 8 8 2
A SummonerMastery.top 4 4 2
A SummonerMastery.level 12 12 1
A SummonerMastery.champion 8 8 1
A SummonerMastery.top 9 9 2
A mastery.js ➔ SummonerMastery 5 5 1
A SummonerMastery.points 7 7 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1 View Code Duplication
"use strict";
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
Object.defineProperty(exports, "__esModule", { value: true });
3
var utils_1 = require("./utils");
4
var SummonerMastery = /** @class */ (function () {
5
    function SummonerMastery(APIKEY, region, summonerId) {
6
        this.summonerId = summonerId;
7
        this.APIKEY = APIKEY;
8
        this.region = region;
9
    }
10
    SummonerMastery.prototype.level = function (callback) {
11
        var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/scores/by-summoner/"
12
            + (this.summonerId + "?api_key=" + this.APIKEY);
13
        utils_1.getJSON(url, function (res, err) {
14
            if (err) {
15
                callback(null, err);
16
            }
17
            else {
18
                callback(res.data);
19
            }
20
        });
21
    };
22
    SummonerMastery.prototype.points = function (callback) {
23
        var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
24
            + (this.summonerId + "?api_key=" + this.APIKEY);
25
        utils_1.getJSON(url, function (res) {
26
            var points = 0;
27
            res.data.forEach(function (champion) {
28
                points += champion.championPoints;
29
            });
30
            callback(points);
31
        });
32
    };
33
    SummonerMastery.prototype.top = function (amount, callback) {
34
        if (amount === void 0) { amount = 0; }
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
35
        var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
36
            + (this.summonerId + "?api_key=" + this.APIKEY);
37
        utils_1.getJSON(url, function (res) {
38
            var slice = amount === 0 ? res.data.length : amount;
39
            callback(res.data.slice(0, slice));
40
        });
41
    };
42
    SummonerMastery.prototype.champion = function (champion, callback) {
43
        if (Array.isArray(champion)) {
44
            var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
45
                + (this.summonerId + "?api_key=" + this.APIKEY);
46
            var returner_1 = [];
47
            utils_1.getJSON(url, function (res) {
48
                res.data.forEach(function (element) {
49
                    if (champion.indexOf(element.championId) !== -1) {
50
                        returner_1.push(element);
51
                    }
52
                });
53
                callback(returner_1);
54
            });
55
        }
56
        else {
57
            var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable url already seems to be declared on line 44. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
58
                + (this.summonerId + "/by-champion/" + champion + "?api_key=" + this.APIKEY);
59
            utils_1.getJSON(url, function (res, err) {
60
                if (err) {
61
                    callback(null, err);
62
                }
63
                else {
64
                    callback(res.data);
65
                }
66
            });
67
        }
68
    };
69
    return SummonerMastery;
70
}());
71
exports.SummonerMastery = SummonerMastery;
72
//# sourceMappingURL=mastery.js.map